Fixed integer overflow in e1000e
PATCH v2 1/1 Fixed integer overflow in e1000e
From: Andrew Melnychenko <[email protected]>
Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.
--- hw/net/e1000e.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic =qemu_new_nic (&net_e1000e_info, &s->conf,object_get_typename (OBJECT (s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues -1 ; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;trace_e1000e_mac_set_permanent (MAC_ARG (macaddr));memcpy (s->core.permanent_mac, macaddr,sizeof (s->core.permanent_mac));
Signature · 1 line
2.24.1
Quoted 5 lines · On 3/4/20 3:20 PM, [email protected] wrote:
From: Andrew Melnychenko <[email protected]>
Fixes 6f3fbe4ed06Fixed setting
max_queue_numif there are no peers in NICConf.qemu_new_nic()creates NICState with 1 NetClientState(index 0) without peers, setmax_queue_numto 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.
Hoping the maintainer taking this can reformat the commit description a bit nicer... (moving the tags down), then for the code part:
Quoted 20 lines
Signed-off-by Andrew Melnychenko <[email protected]>--- hw/net/e1000e.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/net/e1000e.c +1
-1@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic =qemu_new_nic (&net_e1000e_info, &s->conf,object_get_typename (OBJECT (s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues -1 ; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;trace_e1000e_mac_set_permanent (MAC_ARG (macaddr));memcpy (s->core.permanent_mac, macaddr,sizeof (s->core.permanent_mac));
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · On 3/4/20 3:20 PM, [email protected] wrote:
From: Andrew Melnychenko <[email protected]>
Fixes 6f3fbe4ed06Fixed setting
max_queue_numif there are no peers in NICConf.qemu_new_nic()creates NICState with 1 NetClientState(index 0) without peers, setmax_queue_numto 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.Hoping the maintainer taking this can reformat the commit description a bit nicer... (moving the tags down), then for the code part:
Yes, I tweak the log.
Thanks
Quoted 24 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 20 lines
Signed-off-by Andrew Melnychenko <[email protected]>---
hw/net/e1000e.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/net/e1000e.c +1
-0@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic = qemu_new_nic(&net_e1000e_info, &s->conf, object_get_typename(OBJECT(s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues - 1; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ; trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
Quoted 9 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:
From: Andrew Melnychenko <[email protected]>
Fixes 6f3fbe4ed06Fixed setting
max_queue_numif there are no peers in NICConf.qemu_new_nic()creates NICState with 1 NetClientState(index 0) without peers, setmax_queue_numto 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.Signed-off-by Andrew Melnychenko <[email protected]>
Quoted 20 lines
---
hw/net/e1000e.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/net/e1000e.c +1
-1@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic =qemu_new_nic (&net_e1000e_info, &s->conf,object_get_typename (OBJECT (s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues -1 ; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;trace_e1000e_mac_set_permanent (MAC_ARG (macaddr));memcpy (s->core.permanent_mac, macaddr,sizeof (s->core.permanent_mac));Signature · 1 line
2.24.1
Quoted 11 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:
From: Andrew Melnychenko <[email protected]>
Fixes 6f3fbe4ed06Fixed setting
max_queue_numif there are no peers in NICConf.qemu_new_nic()creates NICState with 1 NetClientState(index 0) without peers, setmax_queue_numto 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.Signed-off-by Andrew Melnychenko <[email protected]>
Quoted 20 lines
---
hw/net/e1000e.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/net/e1000e.c +1
-1@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic =qemu_new_nic (&net_e1000e_info, &s->conf,object_get_typename (OBJECT (s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues -1 ; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;trace_e1000e_mac_set_permanent (MAC_ARG (macaddr));memcpy (s->core.permanent_mac, macaddr,sizeof (s->core.permanent_mac));Signature · 1 line
2.24.1
Jason Wang
AppliedQuoted 11 lines · Dmitry Fleytman
Quoted 10 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:
From: Andrew Melnychenko <[email protected]>
Fixes 6f3fbe4ed06Fixed setting
max_queue_numif there are no peers in NICConf.qemu_new_nic()creates NICState with 1 NetClientState(index 0) without peers, setmax_queue_numto 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.Signed-off-by Andrew Melnychenko <[email protected]>Reviewed-by Dmitry Fleytman <[email protected]>
Applied.
Thanks
Quoted 21 lines
Quoted 21 lines
---
hw/net/e1000e.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/net/e1000e.c +1
-1@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) s->nic =qemu_new_nic (&net_e1000e_info, &s->conf,object_get_typename (OBJECT (s)), dev->id, s); - s->core.max_queue_num = s->conf.peers.queues -1 ; + s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;trace_e1000e_mac_set_permanent (MAC_ARG (macaddr));memcpy (s->core.permanent_mac, macaddr,sizeof (s->core.permanent_mac));Signature · 1 line
2.24.1